/**
 * Created by dh.huang on 2016/9/14.
 */
/**
 *tangzhengxiong 2016/9/14
 * @param array 传入数组
 * @returns {*}
 */
function tranlateArray(array){
  for(var n=0;n<array.length;n++){
    var _message = array[n].Value;
    var _result = [];
    var _length = _message.length;

    for(var i=0;i<_length/3;i++){
      var _obj = [];
      for(var j=i*3;j<(i+1)*3;j++){
        _obj.push(_message[j]);
      }
      _result.push(_obj);
    }
    array[n].Value = _result;
  }
  //返回新的数组
  return array;
}

function getToolData(array){
  var _DataArray= tranlateArray(array);

  //保存所有的线
  var _TempArray = {
    data:[]
  };

  for(var index=0;index<_DataArray.length;index++){
    //偏移
    var  _offset ={
      x:100,
      y:100,
      z:100,
    }
    //一条线
    var _line = {
      "visible": true,
      "active": false,
      "offset":_DataArray[index].original || _offset,
      "color": _DataArray[index].color || 'white',
      "handles": [],
      "seriesIUID":"1.2.156.112572.18161010101313.5325155543.6",//序列ID
      //"instanceNumber":0 //实例的num
    };
    //设置点
    var _handles = [];
    var _length = _DataArray[index].Value.length;
    for(var i=0;i<_length;i++){
      //点
      var _Point = {
        "x": 0,
        "y":0,
        "z":0,
        "highlight": true,
        "active": true,
        "lines": [
          {
            "x":0,
            "y":0,
            "z":0,
          }
        ]
      };
      //起始点
      var _value = _DataArray[index].Value;
      _Point.x=_value[i][0];
      _Point.y=_value[i][1];
      _Point.z=_value[i][2];
      //结束点
      if(i===_length-1){
        _Point.lines[0].x=_value[0][0];
        _Point.lines[0].y=_value[0][1];
        _Point.lines[0].z=_value[0][2];
      }else{
        _Point.lines[0].x=_value[i+1][0];
        _Point.lines[0].y=_value[i+1][1];
        _Point.lines[0].z=_value[i+1][2];
      }
      //
      _handles.push(_Point);
    }
    _line.handles = _handles;
    _TempArray.data.push(_line);
  }
  return _TempArray;
}

/**
 调用示例
 */
function init(){
  var _originalArray= [];
  // var _url =  "Contour.json";
  var _url =  "";
  var _newArray = [];
  $.getJSON(_url,function(data){
    _originalArray = data;
    _newArray = getToolData(_originalArray);
    console.log(JSON.stringify( _newArray,null,4));
  });
}
init();

